package com.android.widget.imgtxtimg;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.view.View;

import java.util.List;
import java.util.ArrayList;

import com.android.widget.demo.R;

public class ImgTxtImgListViewActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imgtxtimg);
        initView();
    }

    private void initView() {
        //make data
        List<ImgTxtImg> list = new ArrayList<ImgTxtImg>();
        
        ImgTxtImg item = new ImgTxtImg("first item",R.drawable.ic_launcher,R.drawable.ic_launcher); 
        ImgTxtImg item1 = new ImgTxtImg("second item",R.drawable.ic_launcher,R.drawable.ic_launcher);
        ImgTxtImg item2 = new ImgTxtImg("third item",R.drawable.ic_launcher,R.drawable.ic_launcher);

        list.add(item);        
        list.add(item1);
        list.add(item2);
        for(int i=0;i<30000;i++) {
            item2 = new ImgTxtImg("third item",R.drawable.ic_launcher,R.drawable.pic1);
            list.add(item2);    
        }
            

        ListView listView = (ListView) findViewById(R.id.listview);
        MyListViewAdapter adapter = new MyListViewAdapter(this,R.layout.listview_item,
                list);    
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ImgTxtImgListViewActivity.this,"item position: "+ position,
                        Toast.LENGTH_LONG).show();
            }
        });
    }
}
